package com.genersoft.iot.vmp.conf;

import com.genersoft.iot.vmp.utils.redis.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.LinkedList;
import java.util.List;

@Component
@Order(5)
public class RedisPortRunner implements CommandLineRunner {
    @Autowired
    private RedisUtil redisUtil;

    public void run(String... args) throws Exception {
        String redisKey = "APPPORT_";
        if (this.redisUtil.hasKey(redisKey + "LIST")) {
            List<Object> list1 = this.redisUtil.scan(redisKey + "*");
            String[] array = list1.<String>toArray(new String[0]);
            this.redisUtil.del(array);
        }
        List<Object> list = new LinkedList();
        for (int i = 28000; i < 28500; i++)
            list.add(Integer.valueOf(i));
        this.redisUtil.lSetList(redisKey + "LIST", list);
    }
}
